﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entities;
using DataAccess;
namespace InsuranceVehicle
{
    public partial class Insurance : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                addListItem();
            }
            getDescription();
        }

        private void addListItem()
        {

            InsuranceTypeAccess db = new InsuranceTypeAccess();
            List<InsuranceTypeInfo> listInsu = db.getListOfInsuranceType();
            foreach (var item in listInsu)
            {
                cbbInsuType.Items.Add(item.InsuranceName);

            }
        }

        protected void cbbInsuType_SelectedIndexChanged(object sender, EventArgs e)
        {
            getDescription();
        }

        public void getDescription()
        {
            string selectedInsurance = cbbInsuType.SelectedItem.ToString();
            InsuranceTypeAccess db = new InsuranceTypeAccess();
            InsuranceTypeInfo i = new InsuranceTypeInfo();
            i = db.getInsuranceByName(selectedInsurance);

            if (i != null)
            {

                txtDescription.Text = i.Description;

            }
            else
            {
                txtDescription.Text = "Not have any Description";
            }
        }
    }
}